package com.lehecai.core.api.game;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.game.ServerRecharge;
import com.lehecai.core.game.ServerStatus;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 游戏组别
 * @author He Wang
 */
public class GameServer extends AbstractApiResultBean{

    public static final String SERVER_ID = "server_id";
    public static final String GAME_ID = "game_id";
    public static final String SERVER_STATUS = "server_status";
    public static final String SERVER_SORT = "server_sort";
    public static final String SERVER_NAME = "server_name";
    public static final String SERVER_RECHARGE_OPEN = "server_recharge_open";
    public static final String AUTH_HOST = "auth_host";
    public static final String API_PLAY = "api_play";
    public static final String API_RECHARGE = "api_recharge";
    public static final String API_QUERY = "api_query";
    public static final String AUTH_SERVER_ID = "auth_server_id";
    public static final String AUTH_APP_ID = "auth_app_id";
    public static final String AUTH_RECHARGE_KEY = "auth_recharge_key";
    public static final String AUTH_PLAY_KEY = "auth_play_key";
    public static final String AUTH_QUERY_KEY = "auth_query_key";

    private String serverId;					//服务器id
    private String gameId;						//游戏id
    private ServerStatus serverStatus;			//服务器状态
    private String serverSort;					//服务器排序
    private String serverName;					//服务器名称
    private ServerRecharge serverRecharge;		//服务器充值
    private String authHost;					//主机地址	
    private String apiPlay;						//接入地址
    private String apiRecharge;					//充值地址						
    private String apiQuery;					//查询地址
    private String authServerId;				//接入服务器id
    private String authAppId;					//appid
    private String authRechargeKey;				//充值key
    private String authQueryKey;				//接入key
    private String authPlayKey;					//查询key

    public static GameServer convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        GameServer server = new GameServer();
        server.serverId = getString(object, "server_id");
        server.gameId = getString(object, "game_id");
        server.setServerStatus(ServerStatus.getItem(getInt(object, "server_status")));        
        server.serverSort = getString(object, "server_sort");
        server.serverName = getString(object, "server_name");
        server.setServerRecharge(ServerRecharge.getItem(getInt(object, "server_recharge_open")));        
        server.authHost = getString(object, "auth_host");
        server.apiPlay = getString(object, "api_play");
        server.apiRecharge = getString(object, "api_recharge");
        server.apiQuery = getString(object, "api_query");
        server.authServerId = getString(object, "auth_server_id");
        server.authAppId = getString(object, "auth_app_id");
        server.authRechargeKey = getString(object, "auth_recharge_key");
        server.authPlayKey = getString(object, "auth_play_key");
        server.authQueryKey = getString(object, "auth_query_key");
        return server;
    }

    public static List<GameServer> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<GameServer> list = new ArrayList<GameServer>();

        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }

    public String getGameId() {
        return gameId;
    }

    public void setGameId(String gameId) {
        this.gameId = gameId;
    }

    public ServerStatus getServerStatus() {
        return serverStatus;
    }

    public void setServerStatus(ServerStatus serverStatus) {
        this.serverStatus = serverStatus;
    }

    public String getServerSort() {
        return serverSort;
    }

    public void setServerSort(String serverSort) {
        this.serverSort = serverSort;
    }

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    public ServerRecharge getServerRecharge() {
        return serverRecharge;
    }

    public void setServerRecharge(ServerRecharge serverRecharge) {
        this.serverRecharge = serverRecharge;
    }

    public String getAuthHost() {
        return authHost;
    }

    public void setAuthHost(String authHost) {
        this.authHost = authHost;
    }

    public String getApiPlay() {
        return apiPlay;
    }

    public void setApiPlay(String apiPlay) {
        this.apiPlay = apiPlay;
    }

    public String getApiRecharge() {
        return apiRecharge;
    }

    public void setApiRecharge(String apiRecharge) {
        this.apiRecharge = apiRecharge;
    }

    public String getApiQuery() {
        return apiQuery;
    }

    public void setApiQuery(String apiQuery) {
        this.apiQuery = apiQuery;
    }

    public String getAuthServerId() {
        return authServerId;
    }

    public void setAuthServerId(String authServerId) {
        this.authServerId = authServerId;
    }

    public String getAuthAppId() {
        return authAppId;
    }

    public void setAuthAppId(String authAppId) {
        this.authAppId = authAppId;
    }

    public String getAuthRechargeKey() {
        return authRechargeKey;
    }

    public void setAuthRechargeKey(String authRechargeKey) {
        this.authRechargeKey = authRechargeKey;
    }

    public String getAuthPlayKey() {
        return authPlayKey;
    }

    public void setAuthPlayKey(String authPlayKey) {
        this.authPlayKey = authPlayKey;
    }

    public String getAuthQueryKey() {
        return authQueryKey;
    }

    public void setAuthQueryKey(String authQueryKey) {
        this.authQueryKey = authQueryKey;
    }
}
